using System;

namespace SpaceTrader.Core
{
    public enum LogLevel
    {
        Debug,
        Info,
        Error,
        Critical
    }

    public class Logger
    {
        #region Delegates

        public delegate void LogChangedEventHandler(object sender, EventArgs e);

        #endregion

        private static readonly Logger instance = new Logger();

        protected string mLogFile = "";

        public Logger()
        {
        }

        public string LogFile
        {
            get { return mLogFile; }
        }

        public static Logger Instance()
        {
            return instance;
        }

        public void Log(string Message, LogLevel Level)
        {
            mLogFile += String.Format("[{0}] {1}: {2}\r\n", Level.ToString(), DateTime.Now.ToShortTimeString(), Message);
            OnLogChanged();
        }

        public void Clear()
        {
            mLogFile = "";
        }

        public event LogChangedEventHandler LogChanged;

        protected virtual void OnLogChanged()
        {
            if (LogChanged != null)
                LogChanged.Invoke(this, new EventArgs());
        }
    }
}